package com.ohos.connect.devicecloud.app.modular.projectuser.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ohos.connect.devicecloud.common.annotation.CommonLog;
import com.ohos.connect.devicecloud.common.pojo.CommonResult;
import com.ohos.connect.devicecloud.common.pojo.CommonValidList;
import com.ohos.connect.devicecloud.app.modular.projectuser.model.entity.ProjectUser;
import com.ohos.connect.devicecloud.app.modular.projectuser.model.dto.ProjectUserAddDTO;
import com.ohos.connect.devicecloud.app.modular.projectuser.param.ProjectUserEditParam;
import com.ohos.connect.devicecloud.app.modular.projectuser.param.ProjectUserIdParam;
import com.ohos.connect.devicecloud.app.modular.projectuser.param.ProjectUserPageParam;
import com.ohos.connect.devicecloud.app.modular.projectuser.service.ProjectUserService;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * APP项目用户控制器
 *
 * @author Dongtao
 * @date  2024/12/05 11:05
 */
@Api(tags = "项目成员接口")
@ApiIgnore
@ApiSupport(author = "Dongtao", order = 1)
@RestController
@RequestMapping(value = "/api/v1/device_cloud/app/projectuser")
@Validated
public class ProjectUserController {

    @Resource
    private ProjectUserService projectUserService;

    /**
     * 获取APP项目用户分页
     *
     * @author Dongtao
     * @date  2024/12/05 11:05
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取项目用户分页")
    @GetMapping("/page")
    public CommonResult<Page<ProjectUser>> page(ProjectUserPageParam projectUserPageParam) {
        return CommonResult.data(projectUserService.page(projectUserPageParam));
    }

    /**
     * 添加APP项目用户
     *
     * @author Dongtao
     * @date  2024/12/05 11:05
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加项目用户")
    @CommonLog("添加项目用户")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid ProjectUserAddDTO projectUserAddDTO) {
        projectUserService.add(projectUserAddDTO);
        return CommonResult.ok();
    }

    /**
     * 编辑APP项目用户
     *
     * @author Dongtao
     * @date  2024/12/05 11:05
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑项目用户")
    @CommonLog("编辑项目用户")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid ProjectUserEditParam projectUserEditParam) {
        projectUserService.edit(projectUserEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除APP项目用户
     *
     * @author Dongtao
     * @date  2024/12/05 11:05
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除项目用户")
    @CommonLog("删除项目用户")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   CommonValidList<ProjectUserIdParam> projectUserIdParamList) {
        projectUserService.delete(projectUserIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取APP项目用户详情
     *
     * @author Dongtao
     * @date  2024/12/05 11:05
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取项目用户详情")
    @GetMapping("/detail")
    public CommonResult<ProjectUser> detail(@Valid ProjectUserIdParam projectUserIdParam) {
        return CommonResult.data(projectUserService.detail(projectUserIdParam));
    }
}
